package com.jeegit.ecms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeegit.common.annotation.Log;
import com.jeegit.common.enums.BusinessType;
import com.jeegit.ecms.domain.CmsVideo;
import com.jeegit.ecms.domain.CmsVideoTeacher;
import com.jeegit.ecms.service.ICmsVideoService;
import com.jeegit.ecms.utils.ECMSUtils;
import com.jeegit.common.core.controller.BaseController;
import com.jeegit.common.core.domain.AjaxResult;
import com.jeegit.common.utils.poi.ExcelUtil;
import com.jeegit.common.core.page.TableDataInfo;

/**
 * 录播课程Controller
 * 
 * @author jeegit
 * @date 2022-06-30
 */
@Controller
@RequestMapping("/ecms/video")
public class CmsVideoController extends BaseController
{
    private String prefix = "ecms/video";

    @Autowired
    private ICmsVideoService cmsVideoService;

    @RequiresPermissions("ecms:video:view")
    @GetMapping()
    public String video()
    {
        return prefix + "/video";
    }

    /**
     * 查询录播课程列表
     */
    @RequiresPermissions("ecms:video:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsVideo cmsVideo)
    {
        startPage();
        List<CmsVideo> list = cmsVideoService.selectCmsVideoList(cmsVideo);
        return getDataTable(list);
    }

    /**
     * 导出录播课程列表
     */
    @RequiresPermissions("ecms:video:export")
    @Log(title = "录播课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsVideo cmsVideo)
    {
        List<CmsVideo> list = cmsVideoService.selectCmsVideoList(cmsVideo);
        ExcelUtil<CmsVideo> util = new ExcelUtil<CmsVideo>(CmsVideo.class);
        return util.exportExcel(list, "录播课程数据");
    }

    /**
     * 新增录播课程
     */
    @GetMapping("/add")
    public String add(CmsVideo cmsVideo, ModelMap mmap)
    {
    	CmsVideo.initListTeacher(cmsVideo);
    	mmap.put("cmsVideo", cmsVideo);
    	
        return prefix + "/add";
    }

    /**
     * 新增保存录播课程
     */
    @RequiresPermissions("ecms:video:add")
    @Log(title = "录播课程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsVideo cmsVideo)
    {
        return toAjax(cmsVideoService.insertCmsVideo(cmsVideo));
    }

    /**
     * 修改录播课程
     */
    @RequiresPermissions("ecms:video:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsVideo cmsVideo = cmsVideoService.selectCmsVideoById(id);
        CmsVideo.initListTeacher(cmsVideo);
        mmap.put("cmsVideo", cmsVideo);
        return prefix + "/edit";
    }

    /**
     * 修改保存录播课程
     */
    @RequiresPermissions("ecms:video:edit")
    @Log(title = "录播课程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsVideo cmsVideo)
    {
        return toAjax(cmsVideoService.updateCmsVideo(cmsVideo));
    }

    /**
     * 删除录播课程
     */
    @RequiresPermissions("ecms:video:remove")
    @Log(title = "录播课程", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsVideoService.deleteCmsVideoByIds(ids));
    }
}
